#include "stdio.h"
#include "stdlib.h"
#include "string.h"


char  **getMem(int count)
{
	int i = 0;
	char **tmp = (char **)malloc(count*sizeof(char *));
	for (i=0; i<count; i++)
	{
		tmp[i]  = (char *)malloc(100);
	}
	return tmp;
}

void sortArray(char **myArray, int count)
{
	int i = 0, j = 0;
	char *tmp;
	for (i=0; i<count; i++)
	{
		for (j=i+1; j<count; j++)
		{
			if (strcmp(myArray[i], myArray[j]))
			{
				tmp = myArray[i]; //这个地方交换的是指针变量
				myArray[i] = myArray[j];
				myArray[j] = tmp;
			}
		}
	}
}


void  printfArray(char **myArray, int count)
{
	int i = 0, j = 0;

	for (i=0; i<count; i++)
	{
		printf("%s \n", myArray[i]);
	}
}

void main()
{
	char **pArray = NULL;
	pArray = getMem(3);

	strcpy(pArray[0], "bbbbb");
	strcpy(pArray[1], "aaaa");
	strcpy(pArray[2], "cccc");

	sortArray(pArray, 3);
	//sortArray02(pArray, 3); 

	printf("排序之后\n");
	printfArray(pArray ,3);
	system("pause");


}
